package com.hst.capacity.infra.persistence.jpa.account;

import com.hst.capacity.domain.model.entity.account.SpecialDriverAccountDetailEntity;
import com.hst.capacity.domain.model.response.account.DriverAccountDetailVO;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface SpecialDriverAccountDetailRepository extends JpaRepository<SpecialDriverAccountDetailEntity, String> {

    Page<SpecialDriverAccountDetailEntity> findByIdAccount(String idAccount, PageRequest pageRequest);
    /**
     * 根据订单ID查找司机账户明细信息
     * @param idOrder
     * @return
     */
    SpecialDriverAccountDetailEntity findByRelateOrderNo(String idOrder);

    @Query(" select new com.hst.capacity.domain.model.response.account.DriverAccountDetailVO(ad,os,ov) " +
            " from SpDriverAccountEntity a " +
            " inner join SpecialDriverAccountDetailEntity ad on ad.idAccount = a.idAccount " +
            " inner join SpCarOrderSettlementEntity os on os.idOrder = ad.relateOrderNo " +
            " left join SpCarOrderSettlementViewEntity ov on ov.idOrder = os.idOrder " +
            " where a.ownerId=:idDriver")
    Page<DriverAccountDetailVO> findByIdDriver(String idDriver, PageRequest pageRequest);

    @Query(" select new com.hst.capacity.domain.model.response.account.DriverAccountDetailVO(ad,os,ov) " +
            " from SpecialDriverAccountDetailEntity ad " +
            " inner join SpCarOrderSettlementEntity os on os.idOrder = ad.relateOrderNo " +
            " left join SpCarOrderSettlementViewEntity ov on ov.idOrder = os.idOrder " +
            " where ad.idAccount=:idAccount")
    Page<DriverAccountDetailVO> findVOByIdAccount(String idAccount, PageRequest pageRequest);

}